<?php
namespace App\Http\Controllers\Industry;

use App\Http\Controllers\BaseApiController;
use App\Services\Industry\IndustryService;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Validator;

/**
 * Created by PhpStorm.
 * User: 1
 * Date: 2019/2/19
 * Time: 16:42
 */
class IndustryController extends BaseApiController
{
    private $service;

    public function __construct(IndustryService $service)
    {
        //继承基类的构造方法
        parent::__construct();
        //依赖注入service
        $this->service=$service;
    }
    public function add(Request $request){
        //编写规则
        $rule = [
            'industry_name'=>'required|max:50',
            'industry_img'=>'required|max:200',
            'industry_ishost'=>'required|integer|max:1',
            'industry_sort'=>'required|integer|max:100000',
        ];
        //验证规则,返回错误信息
        //传入rule和接受的数据
        if ($error = $this->validate($rule,$request)){
            return $error;
        }
        //返回添加数据
        return $this->service->add($request);
    }
    public function save(){

    }
    public function sel(){
        //查询8个热门行业
        return $this->service->sel();
    }
    //没有删除的不用补全
    public function del(Request $request){
        //获取行业id
        //编写验证规则
        $rule = ['id'=>'required|max:10000000|integer'];
        //验证是否验证成功
        //传入rule和接受的数据
        if ($error = $this->validate($rule,$request)){
            return $error;
        }
        return $this->service->del($request->get('id'));
    }
}